using System;
using System.Diagnostics;

namespace EaMon
{
    public delegate void EventLogNewEntryHandler(string message);

    public class EventLogMonitor
    {
        public event EventLogNewEntryHandler EventLogNewEntryWritten = delegate(string aevent) { };

        public EventLogMonitor()
        {
            EventLog[] logs = EventLog.GetEventLogs(Environment.MachineName);
            foreach (EventLog log in logs)
            {
                log.EnableRaisingEvents = true;
                log.EntryWritten += LogEntryWritten;    
            }
        }

        private void LogEntryWritten(object sender, EntryWrittenEventArgs e)
        {
            if (e.Entry.EntryType == EventLogEntryType.Error)
                EventLogNewEntryWritten(e.Entry.Message);
        }
    }
}